#!/usr/bin/python
# -*- coding : UTF-8 -*-
# ========================
# @Time  : 2020/6/4 11:12
# @Author: Mecell
# @File  : asset_mysql.py
# ========================

import random

from common.mysql_packaging import MysqlHandle



class AssetMysql(MysqlHandle):
    """
    定义处理资产管理MySQL的类
    """

    def get_all_asset_class(self):
        """
        随机获取所有资产分类等级的信息
        :return:
        """
        asset_class_sql = self.query_conf("asset", "all_asset_class")
        asset_class_info = self(asset_class_sql, args=(0,))
        return asset_class_info


    def get_bottom_asset_class(self):
        """
        随机获取最底层资产分类的信息
        :return:
        """
        asset_class_sql = self.query_conf("asset", "bottom_asset_class")
        asset_class_info = self(asset_class_sql, args=(0,))
        return asset_class_info

    def get_storage_asset_class_id(self):
        """
        随机获取资产库存表的资产上级分类ID
        :return:
        """
        asset_par_id_sql = self.query_conf("asset", "asset_par_id")
        asset_par_id = self(asset_par_id_sql)
        return asset_par_id

    def get_storage_asset_name_id(self):
        """
        随机获取资产库存表的资产名称ID
        :return:
        """
        asset_id_sql = self.query_conf("asset", "asset_id")
        asset_id = self(asset_id_sql)
        return asset_id

    def get_storage_place(self):
        """
        随机获取资产存储地点信息
        :return:
        """
        storage_place_sql = self.query_conf("asset", "storage_place")
        storage_place_detail = self(storage_place_sql)
        return storage_place_detail

    def get_asset_info(self):
        """
        随机获取资产库存信息
        :return:
        """
        asset_sql = self.query_conf("asset", "asset_info")
        asset_info = self(asset_sql)
        return asset_info

    @staticmethod
    def get_asset_state():
        """
        随机获取资产状态
        :return:
        """
        state_id = random.choice([0,1,2,3,6])
        return state_id

    @staticmethod
    def get_unlock_asset_state():
        """
        随机获取非转移锁定的资产状态
        :return:
        """
        state_id = random.choice([0, 1, 2, 3])
        return state_id

    def get_unmatched_emp_dept(self):
        """
        随机获取员工所在部门与查询部门不一致信息
        :return:
        """
        unmatched_emp_dept_sql = self.query_conf("emp", "emp_unmatched_dept")
        unmatched_emp_dept = self(unmatched_emp_dept_sql, args=(1,1))
        return unmatched_emp_dept

    def get_asset_amount(self):
        """
        获取条件下的资产数量
        :return:
        """
        asset_amount_sql = self.query_conf("asset", "asset_amount")
        asset_amount = self(asset_amount_sql, fetch_all=True)
        return asset_amount

    def get_unlock_asset_id(self):
        """
        获取不定量非转移锁定状态的资产ID
        :return:
        """
        asset_id_sql = self.query_conf("asset", "unlock_asset")
        asset_id = self(asset_id_sql, args=(4,), fetch_all=True)
        return asset_id

    def get_lock_asset_id(self):
        """
        获取转移锁定状态的资产ID和资产编码
        :return:
        """
        asset_id_sql = self.query_conf("asset", "lock_asset")
        asset_id = self(asset_id_sql, args=(6,))
        return asset_id

    def get_id_from_transfer_list(self, state):
        """
        获取资产转移列表的id
        :return:
        """
        transfer_id_sql = self.query_conf("asset", "transfer_asset")
        perfected_id_sql = self.query_conf("asset", "perfected_asset")
        transfer_id = self(transfer_id_sql, args=(state, 3), fetch_all=True)
        perfected_id = self(perfected_id_sql, args=(1), fetch_all=True)
        return transfer_id, perfected_id

    def get_transfer_record(self):
        """
        获取资产转移列表的记录
        :return:
        """
        transfer_record_sql = self.query_conf("asset", "transfer_record")
        transfer_record = self(transfer_record_sql)
        return transfer_record

    def get_transfer_apply_list(self):
        """
        获取资产异动转移申请列表数据
        :return:
        """
        transfer_apply_sql = self.query_conf("asset", "transfer_apply")
        transfer_apply = self(transfer_apply_sql)
        return transfer_apply

    def get_transfer_apply_id(self):
        """
        获取资产异动转移申请id
        :return:
        """
        transfer_apply_id_1_sql = self.query_conf("asset", "transfer_apply_id_1")
        transfer_apply_id_1 = self(transfer_apply_id_1_sql)
        transfer_apply_id_2_sql = self.query_conf("asset", "transfer_apply_id_2")
        transfer_apply_id_2 = self(transfer_apply_id_2_sql)
        return transfer_apply_id_1, transfer_apply_id_2

    def get_transfer_change(self):
        """
        获取资产异动转移申请列表数据
        :return:
        """
        not_com_asset_sql = self.query_conf("asset", "not_com_asset")
        is_com_asset_sql = self.query_conf("asset", "is_com_asset")
        lock_not_com_asset_sql = self.query_conf("asset", "lock_not_com_asset")
        not_com_asset = self(not_com_asset_sql, fetch_all=True, args=(32,1,116,116,2))  # 非电脑类-安锦恒-BHRA-2
        is_com_asset = self(is_com_asset_sql, fetch_all=True, args=(32,1,116,116,2))  # 电脑类-安锦恒-BHRA-2
        lock_not_com_asset = self(lock_not_com_asset_sql, fetch_all=True, args=(32,1,116,116,2))  # 非电脑类-安锦恒-BHRA-2
        return not_com_asset, is_com_asset, lock_not_com_asset

    def get_repair_scrap_apply(self, type):
        """
        获取维修/报废申请记录信息
        :return:
        """
        repair_scrap_apply_sql = self.query_conf("asset", "repair_scrap_apply")
        repair_scrap_apply = self(repair_scrap_apply_sql, args=(type,)) # 1 维修 2 报废
        return repair_scrap_apply

    def get_repair_scrap_apply_id(self):
        """
        获取资产异动维修/报废申请id
        :return:
        """
        repair_scrap_apply_id_1_sql = self.query_conf("asset", "repair_scrap_apply_id_1")
        repair_apply_id_1 = self(repair_scrap_apply_id_1_sql, args=(1,))
        scrap_apply_id_1 = self(repair_scrap_apply_id_1_sql, args=(2,))
        repair_scrap_apply_id_2_sql = self.query_conf("asset", "repair_scrap_apply_id_2")
        repair_apply_id_2 = self(repair_scrap_apply_id_2_sql, args=(1,))
        scrap_apply_id_2 = self(repair_scrap_apply_id_2_sql, args=(2,))
        return repair_apply_id_1, repair_apply_id_2, scrap_apply_id_1, scrap_apply_id_2

if __name__ == '__main__':
    asset_sql = AssetMysql()
    # print(AssetMysql().get_all_asset_class())
    # print(AssetMysql().get_bottom_asset_class())
    # print(AssetMysql().get_storage_place())
    # print(AssetMysql().get_asset_info())
    # print(AssetMysql().get_unmatched_emp_dept())
    # print(AssetMysql().get_storage_asset_name_id())
    # print(AssetMysql().get_lock_asset_id())
    # print(AssetMysql().get_asset_amount())
    # print(AssetMysql().get_transfer_change()[1])
    # print(AssetMysql().get_repair_scrap_apply(2))
    print(AssetMysql().get_repair_scrap_apply_id())
    asset_sql.close_sql()
